<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <input type="text" name="" id="word">
    <button id="stage">隐藏密码</button>
</body>
<script>
    let input = document.querySelector('#word');
    let btn = document.querySelector('#stage');

    btn.onclick = function(){
        if(input.type.indexOf('text') != -1){
            input.type = 'password';
            btn.innerHTML = '显示密码';
        }else if(input.type.indexOf('password') != -1){
            input.type = 'text';
            btn.innerHTML = '隐藏密码';
        }else{
            alert('input类型错误');
        }
    }
</script>
</html>